package cn.lingyangwl.agile.food.core.manager;

import cn.hutool.core.collection.CollUtil;
import cn.lingyangwl.agile.model.constants.*;
import cn.lingyangwl.agile.model.module.tenant.TenantContext;
import cn.lingyangwl.agile.food.core.mapper.SkuStockMapper;
import cn.lingyangwl.agile.food.model.entity.GoodsSku;
import cn.lingyangwl.agile.tenant.core.utils.TenantUtils;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 商品sku 仓储层
 *
 * @author shenguangyang
 */
@Slf4j
@Repository
public class GoodsSkuManager extends ServiceImpl<SkuStockMapper, GoodsSku>
    implements IService<GoodsSku> {

    public void deleteByGoodsId(Long goodsId) {
        TenantUtils.execute(
                DataIsolateLevel.MAIN,
                TenantContext.get().getTenantId(), // 这里设置成当前租户id原因是, 只有主租户才能删除
                () -> this.remove(GoodsSku.lqw().eq(GoodsSku::getGoodsId, goodsId))
        );
    }

    public void deleteByGoodsIds(List<Long> goodsIds) {
        if (CollUtil.isEmpty(goodsIds)) {
            return;
        }
        TenantUtils.execute(
            DataIsolateLevel.MAIN,
            TenantContext.get().getTenantId(), // 这里设置成当前租户id原因是, 只有主租户才能删除
            () -> this.remove(GoodsSku.lqw().in(GoodsSku::getGoodsId, goodsIds))
        );
    }
}
